/*Spil, lab et rumskib som bevæger sig ud fra mus
Der skal tilfældigvis komme bomber, hvis rumskibet bliver ramt skal det eksplodere
*/
//Variabler
float randomx = random(1,1280);
float randomx2  = random(1,1280);
float randomx3 = random(1,1280);
int position = 660;
float positiony = -100;
float positiony2 = 0;
int fald = 4;
int tid = 0;
int balls;
int game_over = 0;

//Setup
void setup()
{
  size(1280,720);
  frameRate(60);
  textSize(32);
}

void draw()
{

  background(#ffffff);
  control();
  fill(0,0,0);
    rect(position,690,50,30);
  noFill();
  tid++;
  if(game_over==0)
  {
    shower();
    shower2();
  }
  gameOver();
   

}

void gameOver()
{
  if(positiony > 695 && positiony <= 720 && randomx > position && randomx <= position+55)
  {
    game_over = 1;
  }
  if(positiony2 > 695 && positiony2 <= 720 && randomx2 > position && randomx2<= position+55)
  {
    game_over = 1;
  }
  if(game_over==1)
  {
     text("GAME OVER",100,50); 
     frameRate(1);
    }
}

void shower()
{
    fill(255,60,70);
      ellipse(randomx,positiony,10,10);
    noFill();
    positiony = positiony+fald;
    if (positiony > 720)
    {
    positiony= random(-300,-150);
    randomx = random(1,1280);
    fald = fald+2;
    }

}
void shower2()
{
    fill(255,60,70);
      ellipse(randomx2,positiony2,10,10);
    noFill();
    positiony2 = positiony2+fald;
    if (positiony2 > 720)
    {
    randomx2 = random(1,1280);
    positiony2 = random(-500,-300);
    fald = fald+2;
    }

}

void control()
{
  
    if(fald>=20)
    {
      fald= 20;
    }
  if(key == CODED)
{
    if(keyCode == LEFT && keyPressed==true)
    {
      position = position-10;
    }
    if(keyCode == RIGHT && keyPressed==true)
    {
      position = position +10;
    }

}
  if(position<=0)
  {
    position = 0;
  }
  else if (position >= 1230)
  {
    position = 1230;
  }
  //reset
  if(key=='r' || key=='R')
  {
   game_over=0; 
   frameRate(60);
  }
}

